package rabbit.worker;

import com.rabbitmq.client.Channel;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import rabbit.common.rabbitMqHelper;

import java.io.IOException;
import java.util.concurrent.TimeoutException;


/**
 * Created by root on 17-4-4.
 */
@Component
public class sender {

    private static Logger LOGGER = Logger.getLogger("rabbit.worker.sender");

    //@Autowired
    private rabbitMqHelper _rabbitMqHelper;

    public sender(){
    }

    public sender(rabbitMqHelper rabbitMqHelper){
        this._rabbitMqHelper=rabbitMqHelper;
    }

    public void senMessage(String message){

        try{
            this._rabbitMqHelper.sendMessage(message);
            LOGGER.info("Message :"+message+" has been sent.");
        }
        catch (Exception ex){
            LOGGER.error(ex.getMessage());
        }

    }

    public void closeConnection(){
        try {
            this._rabbitMqHelper.closeConnection();
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
    }

    //next step : send object

}
